package com.lsp.server.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectResult;

import java.io.InputStream;

/**
 * @ClassName FileUploadUtils
 * @Description 文件上传阿里云oss工具类
 * @Author Mr Hao
 * @Date 2021/11/16 9:41
 */
public class FileUploadUtils {
    private static final String  endpoint = "oss-cn-qingdao.aliyuncs.com";
    private static final String  accessKeyId = "LTAI5tSNU3966RHB6M4xFga6";
    private static final String   accessKeySecret = "EMHapg8NsSaFkcqbQyL4gz6s5j9Hb0";
    private static final String bucket="fh-2021";

    public static Object uploadFileOss(InputStream inputStream, String s) {
        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        // 依次填写Bucket名称（例如examplebucket）和Object完整路径（例如exampledir/exampleobject.txt）。Object完整路径中不能包含Bucket名称。
        PutObjectResult putObjectResult = ossClient.putObject(bucket, s, inputStream);
        // 关闭OSSClient。
        ossClient.shutdown();
        return "https://"+bucket+"."+endpoint+"//"+s;
    }
}
